package de.westranger.forex.trading.genetic.allel.fitness;


public final class CompositeFitness {

	private final double profit;
	private final double avgPosProfit;
	private final double avgNegProfit;
	private final double posTrade;
	private final double negTrade;
	private final double counterTakeProfit;
	private final double counterStopLoss;
	private double counterBuy;
	private double counterSell;
	private double sumBuySellRatio;
	private double prodBuySellRatio;
	
	@Deprecated
	public CompositeFitness(final double profit, final double avgPosProfit,	final double avgNegProfit, final double posTrade, final double negTrade, double counterStopLoss, double counterTakeProfit) {
		this.profit = profit;
		this.avgPosProfit = avgPosProfit;
		this.avgNegProfit = avgNegProfit;
		this.posTrade = posTrade;
		this.negTrade = negTrade;
		this.counterStopLoss = counterStopLoss;
		this.counterTakeProfit = counterTakeProfit;
	}
	
	public CompositeFitness(final double profit, final double avgPosProfit,	final double avgNegProfit, final double posTrade, final double negTrade, double counterStopLoss, double counterTakeProfit, final double counterBuy, final double counterSell) {
		this.profit = profit;
		this.avgPosProfit = avgPosProfit;
		this.avgNegProfit = avgNegProfit;
		this.posTrade = posTrade;
		this.negTrade = negTrade;
		this.counterStopLoss = counterStopLoss;
		this.counterTakeProfit = counterTakeProfit;
		this.counterBuy = counterBuy;
		this.counterSell = counterSell;
	}

	@Deprecated
	public CompositeFitness(final double profit, final double avgPosProfit,	final double avgNegProfit, final double posTrade, final double negTrade, double counterStopLoss, double counterTakeProfit, final double counterBuy, final double counterSell, final double sumBuySellRatio,final double prodBuySellRatio) {
		this.profit = profit;
		this.avgPosProfit = avgPosProfit;
		this.avgNegProfit = avgNegProfit;
		this.posTrade = posTrade;
		this.negTrade = negTrade;
		this.counterStopLoss = counterStopLoss;
		this.counterTakeProfit = counterTakeProfit;
		this.counterBuy = counterBuy;
		this.counterSell = counterSell;
		this.sumBuySellRatio = sumBuySellRatio; 
		this.prodBuySellRatio = prodBuySellRatio;
	}

	public double getProfit() {
		return profit;
	}

	public double getAvgPosProfit() {
		return avgPosProfit;
	}

	public double getAvgNegProfit() {
		return avgNegProfit;
	}

	public double getPosTrade() {
		return posTrade;
	}

	public double getNegTrade() {
		return negTrade;
	}
	
	public double calcRatio(){
		//double ratio = ((posTrade/(posTrade+negTrade))*avgPosProfit)+((negTrade/(posTrade+negTrade))*avgNegProfit);
		double ratio = (posTrade*avgPosProfit)+(negTrade*avgNegProfit);
		
		if(ratio <= 0.0 || Double.isNaN(ratio) || Double.isInfinite(ratio)){
			ratio = 0.000001;
		}
		return ratio;
	}
	
	/*
		TRN = prod (sell price / buy price)
		WCT = count of profitable trades
		WRT = (count of profitable trades) / num trades total
		ARN = 1/n *  sum (sell price / buy price) // avg sell buy price ratio

		http://cdn.intechopen.com/pdfs/33405/InTech-Genetic_algorithm_application_for_trading_in_market_toward_stable_profitable_method.pdf
		http://powerswings.com/wp-documents/BECKER_2003-15.pdf
		http://epia2011.appia.pt/LinkClick.aspx?fileticket=EZfzr1SMpU0%3D&tabid=562
		http://scholar.google.de/scholar?hl=de&as_sdt=0,5&q=genetic+programming+overfitting
		http://scholar.google.de/scholar?cites=14922930838402753032&as_sdt=5&sciodt=0&hl=de
		http://www0.cs.ucl.ac.uk/staff/w.yan/gp-evolved-technical-trading.pdf
		http://scholar.google.de/scholar?start=10&hl=de&as_sdt=0&sciodt=0&cites=14922930838402753032&scipsc=
		http://scholar.google.de/scholar?cites=701603128413145352&as_sdt=5&sciodt=0&hl=de
		http://researchrepository.ucd.ie/bitstream/handle/10197/3538/Early_Stopping_Criteria_to_Counteract_Overfitting_in_Genetic_Programming.pdf?sequence=1

		On Overfitting of Technical Market Timing with
		Evolutionary Process
		--- Effects of In-Sample Data Selection--
		To m i o K u ro ka w a 
	 */

	@Deprecated
	public double calcAdvancedFitness(){
		final double trn = this.prodBuySellRatio;
		final double wct = 1.0;//this.posTrade;
		final double wrt = this.posTrade/(this.posTrade+this.posTrade);
		final double arn = (1.0/(this.posTrade+this.posTrade)) * this.sumBuySellRatio;
		double ratio = trn*wct*wrt*arn;

		if(ratio <= 0.0 || Double.isNaN(ratio) || Double.isInfinite(ratio)){
			ratio = 0.000001;
		}
		return ratio;
	}

	public double getCounterTakeProfit() {
		return counterTakeProfit;
	}

	public double getCounterStopLoss() {
		return counterStopLoss;
	}

	public double getCounterBuy() {
		return counterBuy;
	}

	public double getCounterSell() {
		return counterSell;
	}

	public double getSumBuySellRatio() {
		return sumBuySellRatio;
	}

	public double getProdBuySellRatio() {
		return prodBuySellRatio;
	}
}
